/**
 * Copyright (c) 2017, armor All Rights Reserved.
 */

package com.celesea.framework.exception;

import com.celesea.framework.api.Message;
import com.netflix.hystrix.exception.HystrixBadRequestException;

import java.util.Date;

/**
 * 远程调用异常
 *
 * @author <a href="mailto:frankzhiwen@163.com">郑智文(Frank Zheng)</a>
 * @version 0.0.1
 * @date 2017年5月29日
 */
public class RemoteException extends HystrixBadRequestException {

    private static final long serialVersionUID = -4797344137677251038L;

    private String code;

    private ErrorInfo errorInfo;

    /**
     * Creates a new instance of RemoteException
     *
     * @param message
     * @param cause
     */
    public RemoteException(String message, Throwable cause) {
        super(message, cause);
        withCode(Message.REMOTE_ERROR);
    }

    /**
     * Creates a new instance of RemoteException
     *
     * @param message
     */
    public RemoteException(String message) {
        super(message);
        withCode(Message.REMOTE_ERROR);
    }

    public RemoteException withCode(int code) {
        this.code = String.valueOf(code);
        return this;
    }

    /**
     * @return property value of code
     */
    public String code() {
        return code;
    }

    public RemoteException withErrorInfo(ErrorInfo errorInfo) {
        this.errorInfo = errorInfo;
        return this;
    }

    public ErrorInfo errorInfo() {
        return errorInfo;
    }


    public static class ErrorInfo {

        /**
         * 时间戳
         */
        private Date timestamp;

        /**
         * 状态码
         */
        private String status;

        /**
         * 错误信息
         */
        private String error;

        /**
         * 异常类
         */
        private String exception;

        /**
         * 异常消息
         */
        private String message;

        /**
         * 请求调用链
         */
        private String requestChain;

        /**
         * 堆栈信息
         */
        private String trace;

        /**
         * 请求路径
         */
        private String path;

        public Date getTimestamp() {
            return timestamp;
        }

        public void setTimestamp(Date timestamp) {
            this.timestamp = timestamp;
        }

        public String getStatus() {
            return status;
        }

        public void setStatus(String status) {
            this.status = status;
        }

        public String getError() {
            return error;
        }

        public void setError(String error) {
            this.error = error;
        }

        public String getException() {
            return exception;
        }

        public void setException(String exception) {
            this.exception = exception;
        }

        public String getMessage() {
            return message;
        }

        public void setMessage(String message) {
            this.message = message;
        }

        public String getRequestChain() {
            return requestChain;
        }

        public void setRequestChain(String requestChain) {
            this.requestChain = requestChain;
        }

        public String getTrace() {
            return trace;
        }

        public void setTrace(String trace) {
            this.trace = trace;
        }

        public String getPath() {
            return path;
        }

        public void setPath(String path) {
            this.path = path;
        }

    }

}
